'use strict';

const Service = require('egg').Service;

class DistrictsService extends Service {
    // 获取省份列表
    async getProvince() {
        const {
            ctx,
            app
        } = this;
        const res = app.mysql.select('districts', {
            where: {
                deep: 0,
            }, // WHERE 条件
            columns: ['id', 'deep','name','ext_name'], // 要查询的表字段
        });
        return res
    }
    // 获取城市列表
    async getCity() {
        const {
            ctx,
            app
        } = this;
        const {
            pid
        } = ctx.query;
        const res = app.mysql.select('districts', {
            where: {
                deep: 1,
                pid,
            }, // WHERE 条件
            columns: ['id', 'deep','name','ext_name'], // 要查询的表字段
        });
        return res
    }
    // 获取区县列表
    async getCounty() {
        const {
            ctx,
            app
        } = this;
        const {
            pid
        } = ctx.query;
        const res = app.mysql.select('districts', {
            where: {
                deep: 2,
                pid,
            }, // WHERE 条件
            columns: ['id', 'deep','name','ext_name'], // 要查询的表字段
        });
        return res
    }
}

module.exports = DistrictsService;